#include("/template/common/layout/_page_layout.html")
#@layout()

#define css()
<style>

</style>
#end

#define js()
<script type="text/javascript">
    layui.use(['table', 'layer'], function () {
        var table = layui.table
            , $ = layui.jquery
            , button;
        // 表格渲染
        var tableIns = table.render({
            elem: '#dateTable'                  //指定原始表格元素选择器（推荐id选择器）
            , id: 'dateTable'
            , even: true //开启隔行背景
            , size: 'sm' //小尺寸的表格
            , height: 'full-90'    //容器高度
            , contentType: 'application/json; charset=UTF-8'
            , cols: [[                  //标题栏
                {field: 'name', title: '项目名称', minWidth: 150, sort: true}
                , {field: 'projectAssTypeName', title: '项目类型',minWidth:100, sort: true}
                , {field: 'projectAssessmentMode', title: '项目评估方式',width:150, sort: true}
                , {field: 'facAgencyName', title: '申请机构名称',minWidth:150, sort: true}
                , {field: 'createTime', title: '创建时间',width:150, sort: true}
                , {field: 'status', title: '状态',width: 120, sort: true,
                    templet: '#statusTpl(io.jboot.admin.service.entity.status.system.ProjectUndertakeStatus::me(), "status")'
                }
                , {field: 'reply', title: '回复', minWidth: 100}
                , {fixed: 'right', title: '操作', minWidth: 330, align: 'center', toolbar: '#barOption'}
            ]]
            , url: '#(ctxPath)/app/projectUndertake/projectUndertakeList'
            , method: 'get'
            , request: {
                pageName: 'pageNumber' //页码的参数名称，默认：page
                , limitName: 'pageSize' //每页数据量的参数名，默认：limit
            }
            , page: true
            , limits: [30, 60, 90, 150, 300]
            , limit: 30 //默认采用30
            , loading: true
            , where: { applyOrInvite: false, flag: true }
            , done: function (res, curr, count) {
            }
        });


        table.on('tool(dateTable)', function (obj) {
            var data = obj.data;
            if (obj.event === 'see1') {
                pop_show('查看服务机构资料', '#(ctxPath)/app/project/seeFacAgency?id=' + data.facAgencyID, '1030', '', function () {
                });
            } else if (obj.event === 'see') {
                pop_show('查看项目资料', '#(ctxPath)/app/projectUndertake/see?id=' + data.projectID, '1200', '750', function () {
                });
            } else if (obj.event === 'agree') {
                if (button == 1) {
                    var flag = true;
                } else if (button == 2) {
                    var flag = false;
                }
                layer.confirm('确定接受嘛？(此操作不可逆！)', function (index) {
                    $.post("#(ctxPath)/app/projectUndertake/invite", {
                        id: data.id,
                        invite: 2,
                        flag: flag
                    }, function () {
                        layer.msg("同意成功！");
                        setTimeout(function () {
                            if (button == 1) {
                                $('#invite').click();
                            } else if (button == 2) {
                                $('#apply').click();
                            }
                        }, 1000);
                    });
                });
            } else if (obj.event === 'refuse') {
                if (button == 1) {
                    var flag = true;
                } else if (button == 2) {
                    var flag = false;
                }
                layer.open({
                    type: 1
                    , title: false //不显示标题栏
                    , closeBtn: false
                    , area: '300px;'
                    , shade: 0.8
                    , id: 'LAY_layuipro' //设定一个id，防止重复弹出
                    , btn: ['残忍拒绝', '我再想想']
                    , btnAlign: 'c'
                    , moveType: 1 //拖拽模式，0或者1
                    , content: '' +
                    '<div style="padding: 50px; line-height: 22px; background-color: #393D49; color: #fff; font-weight: 300;">' +
                    '<label class="layui-form-label">拒绝缘由</label>' +
                    '<textarea placeholder="请输入内容" class="layui-textarea" name="desc">' +
                    '</textarea>' +
                    '</div>'
                    , success: function (layero) {
                        var btn = layero.find('.layui-layer-btn');
                        btn.find('.layui-layer-btn0').on('click', function () {
                            var textarea = layero.find('textarea')[0];
                            $.post("#(ctxPath)/app/projectUndertake/invite", {
                                id: data.id,
                                reply: textarea.value,
                                invite: 1,
                                flag: flag
                            }, function () {
                                layer.msg("拒绝成功！");
                                setTimeout(function () {
                                    if (button == 1) {
                                        $('#invite').click();
                                    } else if (button == 2) {
                                        $('#apply').click();
                                    }
                                }, 1000);
                            });
                        });
                    }
                });

            }
        });


        $('#applyStatus').on('click', function () {
            table.reload('dateTable', {
                url: '#(ctxPath)/app/projectUndertake/projectUndertakeList'
                , where: {applyOrInvite: false, flag: true} //设定异步数据接口的额外参数
                , cols: [[                  //标题栏
                    {field: 'name', title: '项目名称', minWidth: 150, sort: true}
                    , {field: 'projectAssTypeName', title: '项目类型',minWidth:100, sort: true}
                    , {field: 'projectAssessmentMode', title: '项目评估方式',width:150, sort: true}
                    , {field: 'facAgencyName', title: '申请机构名称',minWidth:150, sort: true}
                    , {field: 'createTime', title: '创建时间',width:150, sort: true}
                    , {field: 'status', title: '状态',width: 120, sort: true,
                        templet: '#statusTpl(io.jboot.admin.service.entity.status.system.ProjectUndertakeStatus::me(), "status")'
                    }
                    , {field: 'reply', title: '回复', minWidth: 100}
                    , {fixed: 'right', title: '操作', minWidth: 330, align: 'center', toolbar: '#barOption'}
                ]]
            });
        });


        $('#invite').on('click', function () {
            button = 1;
            table.reload('dateTable', {
                url: '#(ctxPath)/app/projectUndertake/projectUndertakeList'
                , where: {applyOrInvite: true, flag: false} //设定异步数据接口的额外参数
                , cols: [[                  //标题栏
                    {field: 'name', title: '项目名称', minWidth: 150, sort: true}
                    , {field: 'projectAssTypeName', title: '项目类型',minWidth:100, sort: true}
                    , {field: 'projectAssessmentMode', title: '项目评估方式',width:150, sort: true}
                    , {field: 'facAgencyName', title: '被邀请机构名称',minWidth:150, sort: true}
                    , {field: 'createTime', title: '创建时间',width:150, sort: true}
                    , {field: 'status', title: '状态',width: 120, sort: true,
                        templet: '#statusTpl(io.jboot.admin.service.entity.status.system.ProjectUndertakeStatus::me(), "status")'
                    }
                    , {field: 'reply', title: '回复', minWidth: 100}
                    , {fixed: 'right', title: '操作', minWidth: 330, align: 'center', toolbar: '#barOptionInvite'}
                ]]
            });
        });
    });
</script>
#end

#define content()

<div class="reloadChoose">

    <button class="layui-btn" id="applyStatus">查看申请介入的项目</button>
    <button class="layui-btn" id="invite">查看邀请您介入的项目</button>

</div>

<div class="layui-fluid">
    <div class="layui-row">
        <table id="dateTable" lay-filter="dateTable"></table>
    </div>
</div>

<script type="text/html" id="barOption">
    #shiroHasPermission('/app/projectUndertake/see')
    <a class="layui-btn layui-btn-xs" lay-event="see">查看项目资料</a>
    <label>
        <input class="layui-hide project-id" name="id" value="{{ d.id }}">
    </label>

    <a class="layui-btn layui-btn-xs" lay-event="see1">申请介入服务机构详情</a>

    #end

</script>
<script type="text/html" id="barOptionInvite">
    #shiroHasPermission('/app/projectUndertake/see')
    <a class="layui-btn layui-btn-xs" lay-event="see">查看项目资料</a>
    <label>
        <input class="layui-hide project-id" name="id" value="{{ d.id }}">
    </label>

    <a class="layui-btn layui-btn-xs" lay-event="see1">被邀请服务机构详情</a>
    #end

    #[[
    {{#  if(d.status == '0'){ }}
    ]]#
    #shiroHasPermission('/app/projectUndertake/invite')
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="agree">同意</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="refuse">拒绝</a>
    #end
    #[[
    {{#  } }}
    ]]#
</script>
#end

